/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.ex;

import java.util.Arrays;

/**
 * <p>Project: jse2204 - Ex14
 * <p>Powered by webrx On 2022-09-14 09:15:51
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex14 {
    public static void main(String[] args) {
        System.out.println("hellojava".concat("java1.8").concat("java19").contains("java"));
        System.out.println("hellojava-java18-java19".indexOf("java"));
        System.out.println("hellojava-java18-java19".lastIndexOf("java"));
        System.out.println();
        System.out.println("hellojava-java18-java19".indexOf("java",15));

        //检查字符出现的次数
        String str = "javascripthellojava-java18-java19java";
        char c = 'a';
        int num = 0;
        for(char ch : str.toCharArray()){
            if(c==ch){
                ++num;
            }
        }
        System.out.println(num);

        System.out.println();
        //检查字符串出现的次数
        String s = "java";
        System.out.printf("字符串：\"%s\"，在字符串%s中出现%d次。%n",s,str,str.split("java").length-1);

        //正确的。
        int index = 0;
        num = 0;
        while((index = str.indexOf(s,index)) !=-1){
            num++;
            index+=s.length();
          }
        System.out.printf("字符串：\"%s\"，在字符串%s中出现%d次。%n",s,str,num);

        System.out.println();
        System.out.println(Arrays.toString(str.split("java")));
    }
}
